草庐IT

javascript - 上传到 Cloudinary API - 文件参数无效

全部标签

Ruby 在 1 行代码中读取/写入文件

我是Ruby的新手,我正在练习一些套路,但我遇到了这个愚蠢的问题。我需要用1行代码将1个文件的内容复制到一个新文件第一次尝试:File.open(out,'w').write(File.open(in).read)很好,但是我需要关闭文件是错误的:File.open(out,'w'){|outf|outf.write(File.open(in).read)}然后当然是关闭阅读:File.open(out,'w'){|outf|File.open(in){|inf|outf.write(outf.read))}}这是我想出的,但对我来说它不像1行代码:(想法?问候,

ruby-on-rails - 使用传入的参数在 ActiveAdmin 中的模型上按方法过滤

使用Rails4.2.1和ActiveAdmin1.0.0.pre2我有一个有很多人入住的公寓模型。我希望管理员能够查看索引中的公寓是否与作为参数传入的日期重叠。我有一个关于公寓的方法defavailable_during(start_date,end_date)return!self.occupancies.any?{|occ|occ.date_range_overlap(Date.parse(start_date),Date.parse(end_date))}end如果公寓有任何与两个给定日期重叠的入住,则返回true。关于占用的方法date_range_overlap很容易解释。

ruby - 使用 roo gem 在 ruby​​ 中写入 excel 文件

我正在使用Roogem解析Excel和Excelx文件。但我不确定如何写入这些文件。set_value(row,column,text)方法无效。代码@oo=Excelx.new('tes.xlsx')@oo.default_sheet=@oo.sheets.firstdefreturn_columnkeywords=["website","url"]keywords.eachdo|keyword|1.upto(@oo.last_column)do|n|data=@oo.cell(1,n)returnnifdata.downcase=~/#{keyword}/iendendenddef

ruby - 如何在 Ruby 中为 splat 参数设置默认值

为splat参数设置默认值会产生错误:1.9.3-p374:001>defab,*c=nil1.9.3-p374:002?>endSyntaxError:(irb):1:syntaxerror,unexpected'=',expecting';'or'\n'defab,*c=nil^from/Users/me/.rvm/rubies/ruby-1.9.3-p374/bin/irb:16:in`'我尝试过的一些变体也不起作用:1.9.3-p374:003>defab,*c=[]1.9.3-p374:005>defab,(*c)=nil1.9.3-p374:007>defab,(*c=[]

ruby-on-rails - 错误 : When assigning attributes, 您必须将散列作为参数传递

嗨,我刚开始使用ruby​​,我正在编写Controller和Controller规范,但我遇到了一些问题。文档.rbclassDocument文档Controller.rbclassAPI::DocumentsControllerdocuments_controller_spec.rbdescribe"POST'index'"dobefore{@attr=FactoryGirl.attributes_for(:document)}describe"failure"dodescribe"withmissingparameters"dobefore{@attr.each{|key,val

ruby-on-rails - Rails Engines : When to put code in app, 何时在 lib 中,何时在 vendor 文件夹中?

我正在开发一个Rails引擎,所以我对现有引擎进行了一些研究。我注意到他们中的许多人在app中都有文件,但也在lib和vendor中。我很清楚,我应该将任何应该由主机应用程序替换的代码放入app文件夹中(例如,当有一个模型app/user.rb,主机应用程序可以很容易地拥有自己的app/user.rb文件并使用这个而不是引擎的)。但我不确定,何时必须将内容放入lib,何时放入vendor?我想,在vendor中,我应该只放置我想在我的项目中使用的来自其他开发人员或项目的“外部”代码,而在lib中,我放置我的拥有我在项目中实际使用的其他库。但是,例如,为什么WiceGrid将内容放入其w

ruby-on-rails - "require File.dirname(__FILE__)"-- 如何安全地解除文件系统依赖?

我正在使用的一些Ruby库使用这样的require语句:requireFile.dirname(__FILE__)+'/specification_helper.rb'lib_dir=File.expand_path(File.join(File.dirname(__FILE__),"lib"))requireFile.join(File.dirname(__FILE__),'lib/tools','version')requireFile.expand_path(File.join(File.dirname(__FILE__),'datautils','conn'))这种格式不会使您

ruby - 将数字签名插入现有的 pdf 文件

我需要使用Rails应用程序服务器将数字签名插入到现有的pdf文件中。(基本上,客户端上传pdf文件,服务器用本地证书签名)我一直在使用JSignpdf将数字签名插入pdf文件,并开始探索ruby​​的gems...我在ruby​​pdf网站上找到了另一个可移植文件来完成这项工作http://soft.rubypdf.com/software/pdf-digital-signe,但在ruby​​中找不到任何gem甚至示例代码来执行此操作。我也看过DigitalsignatureverificationwithOpenSSL,但无法理解如何使用本地证书文件对现有文档进行实际签名。我也在h

ruby - gemspec 文件中的 `files` 、 `executables` 、 `test_files` 和 `require_paths` 是什么?

我不清楚.gemspec文件中的某些规范在做什么。具体来说,spec.files=`gitls-files-z`.split("\x0")spec.executables=spec.files.grep(%r{^bin/}){|f|File.basename(f)}spec.test_files=spec.files.grep(%r{^(test|spec|features)/})spec.require_paths=["lib"]谁能解释一下这些与RubyGem的功能有何关系以及为什么需要它们? 最佳答案 executables:

ruby-on-rails - 使用回形针上传多个文件

我在使用回形针上传多个文件时遇到问题,我的模型是这样的sliderhas_manyimgarraysimgarrayshas_manyimageobjectsimageobjectshave_attachment(asforpaperclip)我在接收单个图像并在我的其他模型上使用回形针保存它没有问题,但我不确定如何在多个文件上传期间处理imgarrays参数返回的数组。这是我的Rails服务器日志:StartedPOST"/slider"for127.0.0.1at2012-07-2310:14:17+0800ProcessingbySliderController#createas